<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>

<div class="easyui-layout" fit="true" id="createWoForm">
	<div region="center" border="false">
		<div class="easyui-layout" fit="true" >
			  <t:formvalid formid="formobj" dialog="true"  layout="table" action="" beforeSubmit="" >
			    <div region="north"  style="height:150px;" >
			        <!-- 客户信息表单 -->
			        <div class="easyui-panel" title='客户信息' style="padding: 10px;" fit="true" border="false" id="customser_info">
			          
					        <table style="width: 100%;" cellpadding="0" cellspacing="1" class="formtable" align="center">
						        <tr height="30">
									<td  width="15%" align="center"><label class="Validform_label">客户编号 </label></td>
									<td  class="value" width="35%">
						                <input id="customerNo" style="width:100%;" name="customerNo" value="">
						            </td>
						            
						            <td width="15%" align="center"><label class="Validform_label"><span style="color:red;">&nbsp;&nbsp;</span> 客户名称 </label></td>
									<td class="value" width="35%">
						                <input id="customerName"  style="width:100%;"  name="customerName" value="">
						            </td>
								</tr>
						         <tr height="30">
							            <td width="15%" align="center"><label class="Validform_label"><span style="color:red;">*</span> 联系人 </label></td>
										<td class="value" width="35%">
							                <input id="contactMan"  style="width:100%;"  name="contactMan" value="">
							            </td>
							            <td width="15%" align="center"><label class="Validform_label"><span style="color:red;">&nbsp;&nbsp;</span> 联系地址 </label></td>
										<td class="value" width="35%">
							                <input id="contactAddress"  style="width:100%;"  name="contactAddress" value="">
							            </td>
							            
								</tr>
								<tr height="30">
								        <td  width="15%" align="center"><label class="Validform_label"><span style="color:red;">*</span> 联系电话</label></td>
										<td  class="value" width="35%">
							                <input id="contactPhone" style="width:100%;" name="contactPhone" value="">
							            </td>
										<td  width="15%" align="center"><label class="Validform_label"><span style="color:red;">&nbsp;&nbsp;</span> 联系电话2 </label></td>
										<td  class="value" width="35%">
							                <input id="contactPhone2" style="width:100%;" name="contactPhone2" value="">
							            </td>
							            
							            
								</tr>
					        </table>
			          
			        </div>
			     </div>
			  
			    <div region="center" style="" split="true">
			        <!-- 受理信息表单 -->
			        <div class="easyui-panel" title='受理信息' style="padding: 10px;" fit="true" border="false" id="accept_info">
			           <table style="width: 100%;" cellpadding="0" cellspacing="1" class="formtable" align="center">
					        <tr height="30">
								<td  width="15%" align="center"><label class="Validform_label"><span style="color:red;">*</span> 工单来源</label></td>
								<td  class="value" width="35%" >
								    <select name="woSrc" id="woSrc" style="margin-left:5px;width:140px;" value="A01">	                                 
								         <option value="A01">95598工单</option>
		                              
							        </select>	
					            </td>
					            <td  width="15%" align="center"><label class="Validform_label"><span style="color:red;">&nbsp;&nbsp;</span> 关联工单</label></td>
								<td  class="value" width="35%" >
									<!-- 保存状态默认为提交:1 -->
								    <input type="hidden" value="1" name="saveState" id="saveState"/>
								    <input type="hidden" name="woAssos" id="woAssos"/>
					                <label id="lblAssoWos"></label>
					            </td>					            
							</tr>
							<tr height="30"  id="tr_95598_wo">
								<td  width="15%" align="center"> <label class="Validform_label" ><span style="color:red;">*</span> 95598工单编号  </label></td>
								<td  class="value" width="35%">
					                 <input id="wo95598Id" style="width:100%;" name="wo95598Id" value="">
					            </td>
					            <td  width="15%" align="center"><label class="Validform_label"><span style="color:red;">*</span> 受理时间 </label></td>
					            <td  class="value" width="35%">
					                 <input class="Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" style="width: 150px;" id="acDatetime"
						      				 name="acDatetime" ignore="ignore" value="">
					            </td>
							</tr>
							<tr>
								<td  width="15%" align="center"><label class="Validform_label"><span style="color:red;">*</span> 工单类型 </label></td>
								<td  class="value" width="35%" >
					                <select name="woType" id="woType" style="margin-left:5px;width:140px;" onchange="setOverTime(this.value)">
								         <option value="">请选择</option>					                      
							        </select>
					            </td>
					            <td  width="15%" align="center"> <label class="Validform_label"><span style="color:red;">*</span> 办结时限 </label></td>
								<td  class="value" width="35%" >
					                 <input class="Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" style="width: 150px;" id="overTime"
						      				 name="overTime" ignore="ignore" value="">
					            </td>
							</tr>
							
							<tr>
								<td  width="15%" align="center"><label class="Validform_label"><span style="color:red;">*</span> 受理内容</label></td>
								<td  class="value" width="85%" colspan="3">
					                <textarea style="height:100px;width:100%;border:0px;" id="woContent" name="woContent"  maxlength="500"></textarea>
					            </td>
							</tr>
							<tr>
								<td  width="15%" align="center"><label class="Validform_label"><span style="color:red;">&nbsp;&nbsp;</span> 受理意见</label></td>
								<td  class="value" width="85%"  colspan="3">
					                <textarea style="height:90px;width:100%;border:0px;" id="woOpinion" name="woOpinion"  maxlength="500"></textarea>
					            </td>
							</tr>
							
							
							<tr height="30">
								<td  width="15%" align="center"><label class="Validform_label"><span style="color:red;">&nbsp;&nbsp;</span> 操作选项</label></td>
								<td  class="value" width="85%"  colspan="3">
								    <select name="woState" id="woState" style="margin-left:10px;width:120px;height:30px;">
					                     <!-- 遍历工单状态-->			
			                             <c:forEach var="woState" items="${woStateList }" > 
								             <option value="${woState.woStateCode }">${woState.woStateDesc }</option>
								         </c:forEach>
							        </select>
							        <span id="selectDeparton">
								        <label style="padding:2px;">主办</label><input id="zDepartname" name="zDepartname" type="text" style="height:30px;width:100px;" readonly="readonly" class="inputxt"   onclick="openZDepartmentSelect();" value="">
				                        <input id="zOrgIds" name="zOrgIds" type="hidden" value="">
				                        <label style="padding:2px;">协办</label><input id="xDepartname" name="xDepartname" type="text" style="height:30px;width:100px;" readonly="readonly" class="inputxt"   onclick="openXDepartmentSelect();" value="">
				                        <input id="xOrgIds" name="xOrgIds" type="hidden" value="">
				                        
			                        </span>
					            </td>
							</tr>
						</table>
						 <table style="width: 100%;" cellpadding="0" cellspacing="1"  border="0" align="center" >
						    <tr height="60">
								<td  width="15%" align="center">&nbsp;</td>
								<td  class="value" width="85%" >							        
							        <a href="#" class="easyui-linkbutton"  plain="true" style="margin-left:30px;" onclick="mysubmit();" iconCls="icon-save">确 定</a>
							        <a href="#" class="easyui-linkbutton"  plain="true" style="margin-left:15px;" onclick="myreset();" iconCls="icon-cancel">清 空</a>
					            </td>
							</tr>
						   
						 </table>
					
						
						
			        </div>
		        </div>
		   </t:formvalid>
		 </div>
	</div>
	
		
	<div data-options="region:'east',
			title:'历史工单',
			collapsed:true,
			split:true,
			border:false,
			onExpand : function(){
				li_east = 1;
			},
			onCollapse : function() {
			    li_east = 0;
			}"
			style="width: 500px; overflow: hidden;" id="eastPanel">
		     <!-- 历史工单列表 -->
			 <t:datagrid  name="historyWOGrid" title="" actionUrl="woController.do?historyWOGrid" idField="id" treegrid="false" pagination="true"  sortOrder="desc" sortName="createDatetime" onLoadSuccess="">
	            <t:dgCol title="工单编号" field="id" width="90" ></t:dgCol>	           
	            <t:dgCol title="客户名称 " field="customerName" width="130" query="true"></t:dgCol>
	            <t:dgCol title="联系人 " field="contactMan" width="100" query="true"></t:dgCol>
	            <t:dgCol title="联系电话 " field="contactPhone" width="100" query="true"></t:dgCol>	            
	            <t:dgCol title="客户编号" field="customerNo"  hidden="true"></t:dgCol>
	            <t:dgCol title="联系电话2 " field="contactPhone2" hidden="true"></t:dgCol>
	            <t:dgCol title="联系地址 " field="contactAddress" hidden="true"></t:dgCol>
	            
				<t:dgCol title="common.operation" field="opt" width="40"></t:dgCol> 
	            <t:dgFunOpt funname="setAsso(id)" title="关联"></t:dgFunOpt>
	        </t:datagrid>
		</div>
	
</div>

<script type="text/javascript">
	$(function() {
	    var li_east = 0;
	    
	    loadGreidByContactMan();
	    loadGreidByCustomerName();
	    loadGreidByContactPhone();

	    $('#historyWOGrid').datagrid({  
		   onDblClickRow: function (rowIndex, rowData) {  
			   createdetailwindow("工单详情","woController.do?woDetailTabs&wo_id=" + rowData.id,1200,600);
		   },
		   onClickRow: function (rowIndex, rowData) {  	
			    $('#customerNo').val(rowData.customerNo);
			    $('#customerName').val(rowData.customerName);
			    $('#contactPhone').val(rowData.contactPhone);
			    $('#contactMan').val(rowData.contactMan);
			    $('#contactPhone2').val(rowData.contactPhone);
			    $('#contactAddress').val(rowData.contactAddress);
			   
		    } 
	   });
	    
	    $('#woState').change(function(){ 
			   var p1=$(this).val();
			   if(p1=='S03'){
				   $('#selectDeparton').show();
			   }else{
				   $('#selectDeparton').hide();
			   }
	   });
	    
	    selectType('A01');
	});
	
	function loadGreidByContactMan(){
		 $("#contactMan").blur(function(){
		    	var v = this.value.trim();
		    	if(v!=''){
		    		$('#historyWOGrid').datagrid({  
		    			queryParams:{ 'contactMan' : v },
			    		onLoadSuccess: function (data) {
			    			if(data.total>0){
	
			    				if(li_east == 0 ){
			    	                $('#createWoForm').layout('expand','east');  
			    	            }
			    			}
			    	    }
		    	    });
		    		
		    	}
		    	
		    });
	}
	
	function loadGreidByCustomerName(){
		 $("#customerName").blur(function(){
		    	var v = this.value.trim();
		    	if(v!=''){
		    		$('#historyWOGrid').datagrid({  
		    			queryParams:{ 'customerName' : v },
			    		onLoadSuccess: function (data) {
			    			if(data.total>0){
	
			    				if(li_east == 0 ){
			    	                $('#createWoForm').layout('expand','east');  
			    	            }
			    			}
			    	    }
		    	    });
		    		
		    	}
		    	
		    });
	}
	
	function loadGreidByContactPhone(){
		 $("#contactPhone").blur(function(){
		    	var v = this.value.trim();
		    	if(v!=''){
		    		$('#historyWOGrid').datagrid({  
		    			queryParams:{ 'contactPhone' : v },
			    		onLoadSuccess: function (data) {
			    			if(data.total>0){
	
			    				if(li_east == 0 ){
			    	                $('#createWoForm').layout('expand','east');  
			    	            }
			    			}
			    	    }
		    	    });
		    		
		    	}
		    	
		    });
	}
	
	function mysubmit() {
		if($('#contactMan').val().trim()==''){
        	$.messager.alert('&nbsp;&nbsp;信息提醒','联系人不能为空！', 'info');
        	return false;
        }
    	if($('#contactPhone').val().trim()==''){
        	$.messager.alert('&nbsp;&nbsp;信息提醒','联系电话不能为空！', 'info');
        	return false;
        }
    	
    	if($('#woSrc').val()==''){
        	$.messager.alert('&nbsp;&nbsp;信息提醒','请选择工单来源！', 'info');
        	return false;
        }
    	
    	if($('#woSrc').val()=='A01'){
       	  if($('#wo95598Id').val()==''){
       		 $.messager.alert('&nbsp;&nbsp;信息提醒','请输入95598工单编号！', 'info');
       		 return false;
       	  }
       	  
         if($('#acDatetime').val()==''){
      		 $.messager.alert('&nbsp;&nbsp;信息提醒','请输入受理时间！', 'info');
      		 return false;
      	  }
        }
    	
        if($('#woType').val()==''){
        	$.messager.alert('&nbsp;&nbsp;信息提醒','请选择工单类型！', 'info');
        	return false;
        }		        
        if($('#woContent').val()==''){
        	$.messager.alert('&nbsp;&nbsp;信息提醒','请输入受理内容！', 'info');
        	return false;
        }
        
        
        
        var tipMsg = '';
        var woState = $('#woState').val();
        var woStateTxt =  $("#woState").find("option:selected").text();
        if(woState=='S03'){
	        if($('#zOrgIds').val().trim()==''){
	        	$.messager.alert('&nbsp;&nbsp;信息提醒','请选择主办部门！', 'info');
	        	return false;
	        } 
	        tipMsg = '确认【'+woStateTxt+'】到【'+$('#zDepartname').val()+'】吗?';
        }else{
        	tipMsg = '确认【'+woStateTxt+'】吗?';
        }
        $.dialog.setting.zIndex = getzIndex(true);
    	$.dialog.confirm(tipMsg, function(){
	    		$('#formobj').form('submit', {  
	    			url:'woController.do?saveWO',
	    		    onSubmit: function(){  
	    		    	//进行表单验证  
	    		        //如果返回false阻止提交      			    	
	    		    },  
	    		    success:function(data){  
	    		    	var d = $.parseJSON(data);
	    		    	$.messager.alert('信息提醒', d.msg, 'info');
	    		    	myreset();
	    		    }  
	    		}); 
	    	}, function(){
	    });
	}
	
	function myreset() {
		$('#formobj').form('reset'); 
		$('#selectDeparton').show();
		$('#woAssos').val('');
		$('#lblAssoWos').html('');
	
	}
	//工单办结时限
	function setOverTime(typeCode){
		$.ajax({
    		async : false,
    		cache : false,
    		type : 'POST',
    		url : "woController.do?callOverTime&typeCode="+typeCode,
    		error : function() {// 请求失败处理函数
    		},
    		success : function(data) {
    			var d = $.parseJSON(data);
    			if (d.success) {
    				$('#overTime').val(d.msg);    				 
    			}    			
    		}
    	}); 
	}
	//工单类型
	function selectType(woSrc){
		/* if(woSrc=='A01'){
			
			$('#tr_95598_wo').show();
		}else{
			$('#tr_95598_wo').hide();
			
			$('#wo95598Id').val('');
			$('#acDatetime').val('');
		} */
		$.ajax({
    		async : false,
    		cache : false,
    		type : 'POST',
    		url : "woController.do?selectType&woSrc="+woSrc,
    		error : function() {// 请求失败处理函数
    		},
    		success : function(data) {
    			var d = $.parseJSON(data);    			 
    			if (d.success) {
    				$('#woType').empty();
    				$('#overTime').val('');
    				$('#woType').append($("<option>").val("").text("请选择")); 
    				for(var i=0;i<d.obj.length;i++){
    					var t = d.obj[i]; 
    					$('#woType').append($("<option>").val(t.typeCode).text(t.typeName)); 
    				}				 
    			}    			
    		}
    	}); 
	}
	
	//关联工单ID
	function setAsso(wo_id){
		var r = $('#woAssos').val();
		var r_html = $('#lblAssoWos').html();
		
		if(r!=''){
			if(r.indexOf(wo_id)==-1){
				r += ","+wo_id
				r_html += "<span title='点击删除' style='cursor:hand;' onclick='delWo(this)'>,"+wo_id+"</span>";
			}else{
				return;
			}
			
		}else{
			r = wo_id;
			r_html = "<span title='点击删除' style='cursor:hand;' onclick='delWo(this)'>"+wo_id+"</span>";
		}	
		$('#woAssos').val(r);		
		$('#lblAssoWos').html(r_html);
	}
	
	//删除工单ID
	function delWo(wo_id){
		var v = $(wo_id).html();
		$(wo_id).remove();
		var r = $('#woAssos').val();
		r = r.replace(v,"");
		$('#woAssos').val(r);
		
	}
	
	function openZDepartmentSelect() {
		$.dialog.setting.zIndex = 9999; 
		
		var orgIds = $("#zOrgIds").val();
		
		$.dialog({content: 'url:departController.do?departSelect&orgIds='+orgIds, zIndex: 2100, title: '组织机构列表', lock: true, width: '400px', height: '350px', opacity: 0.4, button: [
		   {name: '<t:mutiLang langKey="common.confirm"/>', callback: callbackZDepartmentSelect, focus: true},
		   {name: '<t:mutiLang langKey="common.cancel"/>', callback: function (){}}
	   ]}).zindex();
	}
	
	function callbackZDepartmentSelect() {
		  var iframe = this.iframe.contentWindow;
		  var treeObj = iframe.$.fn.zTree.getZTreeObj("departSelect");
		  var nodes = treeObj.getCheckedNodes(true);
		  if(nodes.length>0){
		  var ids='',names='';
		  for(i=0;i<nodes.length;i++){
		     var node = nodes[i];
		     ids += node.id+',';
		    names += node.name+',';
		 }
		 $('#zDepartname').val(names);
		 $('#zDepartname').blur();		
		 $('#zOrgIds').val(ids);		
		}
	}
	
	function openXDepartmentSelect() {
		$.dialog.setting.zIndex = 9999; 
		
		var orgIds = $("#xOrgIds").val();
		
		$.dialog({content: 'url:departController.do?departSelect&orgIds='+orgIds, zIndex: 2100, title: '组织机构列表', lock: true, width: '400px', height: '350px', opacity: 0.4, button: [
		   {name: '<t:mutiLang langKey="common.confirm"/>', callback: callbackXDepartmentSelect, focus: true},
		   {name: '<t:mutiLang langKey="common.cancel"/>', callback: function (){}}
	   ]}).zindex();
	}
	
	function callbackXDepartmentSelect() {
		  var iframe = this.iframe.contentWindow;
		  var treeObj = iframe.$.fn.zTree.getZTreeObj("departSelect");
		  var nodes = treeObj.getCheckedNodes(true);
		  if(nodes.length>0){
		  var ids='',names='';
		  for(i=0;i<nodes.length;i++){
		     var node = nodes[i];
		     ids += node.id+',';
		    names += node.name+',';
		 }
		 $('#xDepartname').val(names);
		 $('#xDepartname').blur();		
		 $('#xOrgIds').val(ids);		
		}
	}

</script>